package com.ruoyi.supermarket.service.impl;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.supermarket.mapper.SelectedCategoryMapper;
import com.ruoyi.supermarket.domain.SelectedCategory;
import com.ruoyi.supermarket.service.SelectedCategoryService;

/**
 * 精选分类Service业务层处理
 * 
 * @author 李其伟
 * @date 2023-10-24
 */
@Service
public class SelectedCategoryServiceImpl implements SelectedCategoryService
{
    @Autowired
    private SelectedCategoryMapper selectedCategoryMapper;

    /**
     * 查询精选分类
     * 
     * @param id 精选分类主键
     * @return 精选分类
     */
    @Override
    public SelectedCategory selectSelectedCategoryById(Long id)
    {
        return selectedCategoryMapper.selectSelectedCategoryById(id);
    }

    /**
     * 查询精选分类列表
     * 
     * @param selectedCategory 精选分类
     * @return 精选分类
     */
    @Override
    public List<SelectedCategory> selectSelectedCategoryList(SelectedCategory selectedCategory)
    {
        return selectedCategoryMapper.selectSelectedCategoryList(selectedCategory);
    }

    /**
     * 新增精选分类
     * 
     * @param selectedCategory 精选分类
     * @return 结果
     */
    @Override
    public int insertSelectedCategory(SelectedCategory selectedCategory)
    {
        selectedCategory.setPublishStatus(Constants.PUBLISH_STATUS_DOWN);
        return selectedCategoryMapper.insertSelectedCategory(selectedCategory);
    }

    /**
     * 修改精选分类
     * 
     * @param selectedCategory 精选分类
     * @return 结果
     */
    @Override
    public int updateSelectedCategory(SelectedCategory selectedCategory)
    {
        return selectedCategoryMapper.updateSelectedCategory(selectedCategory);
    }

    /**
     * 上下架精选分类
     *
     * @param selectedCategory 精选分类
     * @return 结果
     */
    @Override
    public int publishSelectedCategory(SelectedCategory selectedCategory) {
        SelectedCategory sc = selectedCategoryMapper.selectSelectedCategoryById(selectedCategory.getId());
        sc.setPublishStatus(selectedCategory.getPublishStatus());
        return selectedCategoryMapper.updateSelectedCategory(sc);
    }

    /**
     * 批量删除精选分类
     * 
     * @param ids 需要删除的精选分类主键
     * @return 结果
     */
    @Override
    public int deleteSelectedCategoryByIds(Long[] ids)
    {
        return selectedCategoryMapper.deleteSelectedCategoryByIds(ids);
    }

    /**
     * 删除精选分类信息
     * 
     * @param id 精选分类主键
     * @return 结果
     */
    @Override
    public int deleteSelectedCategoryById(Long id)
    {
        return selectedCategoryMapper.deleteSelectedCategoryById(id);
    }
}
